home *** CD-ROM | disk | FTP | other *** search
- function moveTheBalls()
- {
- x = 1;
- while(theNumberOfBalls >= x)
- {
- thisBall = theBallsList["ball" + x];
- if(!thisBall == 0)
- {
- thisBall.moveBall();
- }
- x++;
- }
- }
- function newBallList(startBallNum)
- {
- this["ball" + startBallNum] = new newBall("ball" + startBallNum);
- }
- function addNewBall()
- {
- theNumberOfBalls++;
- theCurBallNum++;
- theBallsList["ball" + theNumberOfBalls] = new newBall("ball" + theNumberOfBalls);
- }
- function maketargetList(numOfTiles)
- {
- i = 0;
- while(i < numOfTiles)
- {
- gTargetList[i] = String("tile" + (i + 1));
- i++;
- }
- }
- function newBall(instName)
- {
- duplicateMovieClip("ball",instName,16384 + theNumberOfBalls);
- this.name = instName;
- this.MovieClip = _root[instName];
- this.MovieClip._x = gBallBaseLoc[0];
- this.MovieClip._y = gBallBaseLoc[1];
- this.deltaX = getRandom(-5,5);
- this.deltaY = -10;
- this.HitNum = 0;
- }
- function resetGame()
- {
- maketargetList(gTileNum);
- resetTiles();
- }
- function resetTiles()
- {
- i = 0;
- while(i < gTileNum)
- {
- var thisTile = gTargetList[i];
- _root[thisTile]._x = _root[thisTile].startX;
- i++;
- }
- }
- function checkForXtraBall(theBallName)
- {
- var xtraBallNum = xtraBallList.length;
- i = 0;
- while(i < xtraBallNum)
- {
- if(theBallName eq xtraBallList[i])
- {
- return 1;
- }
- i++;
- }
- }
- function getRandom(x, y)
- {
- return Math.round(Math.random() * (y - x)) + x;
- }
- Mouse.hide();
- gameOn = 1;
- theScore = 0;
- gBallBaseLoc = [200,300];
- gThePaddle = [_root.paddle,_root.paddle2];
- gGameRect = [0,0,400,500];
- gHMax = pGameRect[2] - 5;
- gTileNum = 35;
- gTargetList = [];
- maketargetList(gTileNum);
- theNumberOfBalls = 1;
- theCurBallNum = 1;
- theBallsList = new newBallList(theNumberOfBalls);
- ballsLeft = 2;
- xtraBallList = ["tile16","tile18","tile33"];
- _root.resetTiles();
- newBall.prototype.moveBall = function()
- {
- this.MovieClip._x += this.deltaX;
- this.MovieClip._y += this.deltaY;
- if(this.MovieClip._y < 0)
- {
- this.flipY();
- }
- var theTileNum = gTargetList.length;
- i = 0;
- while(i < theTileNum)
- {
- var thisTile = gTargetList[i];
- if(this.MovieClip.hitTest(_root[thisTile]))
- {
- this.increaseSpeed();
- theScore += 10 * theCurBallNum;
- _root[thisTile]._x += -1000;
- gTargetList.splice(i,1);
- this.flipY();
- if(checkForXtraBall(thisTile))
- {
- addNewBall();
- }
- if(gTargetList.length == 0)
- {
- resetGame();
- }
- break;
- }
- i++;
- }
- thisPad = 0;
- while(thisPad < 2)
- {
- var thePaddle = gThePaddle[thisPad];
- if(this.MovieClip.hitTest(thePaddle) && 0 < this.deltaY)
- {
- this.paddleHit(thePaddle);
- }
- thisPad++;
- }
- if(gGameRect[3] + 20 < this.MovieClip._y)
- {
- theBallsList[this.name] = 0;
- removeMovieClip(this.MovieClip);
- theCurBallNum--;
- if(0 >= theCurBallNum)
- {
- ballsLeft--;
- if(ballsLeft < 0)
- {
- ballsLeft = 0;
- gameOn = 0;
- gotoAndStop(6);
- }
- else
- {
- addNewBall();
- }
- }
- }
- if(this.MovieClip._x < gGameRect[0] || gGameRect[2] < this.MovieClip._x)
- {
- this.flipX();
- }
- };
- newBall.prototype.serveBall = function()
- {
- this.MovieClip._x = gBallBaseLoc[0];
- this.MovieClip._y = gBallBaseLoc[1];
- this.deltaX = getRandom(-5,5);
- this.deltaY = -10;
- };
- newBall.prototype.flipY = function()
- {
- this.deltaY *= -1;
- };
- newBall.prototype.flipX = function()
- {
- this.deltaX *= -1;
- };
- newBall.prototype.paddleHit = function(thePaddle)
- {
- this.deltaX = (this.MovieClip._x - thePaddle._x) / 4;
- this.flipY();
- this.MovieClip._y = Math.min(this.MovieClip._y,thePaddle._y + 10);
- };
- newBall.prototype.increaseSpeed = function()
- {
- if(!(this.deltaY < -18 || 18 < this.deltaY))
- {
- this.hitNum = this.hitNum + 1;
- if(3 < this.hitNum)
- {
- this.hitNum = 0;
- if(0 < this.deltaY)
- {
- this.deltaY = this.deltaY + 1;
- }
- else
- {
- this.deltaY--;
- }
- }
- }
- };
-